package com.qf.shop.controller;

import cn.dsna.util.images.ValidateCode;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/code")
public class CreateCodeController extends BaseController {
    public void  createCode(HttpServletRequest request,HttpServletResponse response) throws IOException {
        ValidateCode validateCode = new ValidateCode(100,35,4,1);
        String code = validateCode.getCode();
        request.getSession().setAttribute("code",code);
        validateCode.write(response.getOutputStream());

    }
    public String checkCode(HttpServletRequest request,HttpServletResponse response){
        //获取用户输入
        String vcode = request.getParameter("code");
        String code =(String ) request.getSession().getAttribute("code");
        if(!vcode.isEmpty()&& code.equalsIgnoreCase(vcode)){
            return "0";

        }else{
            return "1";
        }
    }
}

